<template>
  <div class="clubPage">
    <div class="searchBox bgfff">
      <div class="tabsBox">
        <el-tabs v-model="type" @tab-click="handleClick">
          <el-tab-pane label="社团活动" name="1"></el-tab-pane>
          <el-tab-pane label="社团成员" name="2"></el-tab-pane>
        </el-tabs>
        <el-button
          type=""
          size="small"
          @click="
            () => {
              $router.go(-1);
            }
          "
          >返回</el-button
        >
      </div>
      <el-form
        :inline="true"
        :model="form"
        ref="formRef"
        class="demo-form-inline"
        size="small"
      >
        <el-row v-show="type == 1">
          <el-col :span="6">
            <el-form-item label="活动标题：" prop="name">
              <el-input v-model="form.name" placeholder="活动标题"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="活动地址：" prop="address">
              <el-input v-model="form.address" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="上下架状态：" prop="status">
              <el-select v-model="form.status" placeholder="上下架状态">
                <el-option label="全部" :value="0"></el-option>
                <el-option label="上架" :value="1"></el-option>
                <el-option label="下架" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" style="display: flex; justify-content: flex-end">
            <el-form-item style="margin-right: 0">
              <el-button type="primary" size="small" @click="onSubmit"
                >查询</el-button
              >
              <el-button @click="resetForm('formRef')">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row v-show="type == 2">
          <el-col :span="6">
            <el-form-item label="姓名：" prop="userName">
              <el-input v-model="form.userName" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="身份：" prop="type">
              <el-select v-model="form.type" placeholder="请选择身份">
                <el-option label="全部" :value="0"></el-option>
                <el-option label="社长" :value="1"></el-option>
                <el-option label="社团成员" :value="2"></el-option>
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :span="6">
            <el-form-item label="手机号：" prop="mobile">
              <el-input v-model="form.mobile" placeholder="请输入"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="6" style="display: flex; justify-content: flex-end">
            <el-form-item style="margin-right: 0">
              <el-button type="primary" size="small" @click="onSubmit"
                >查询</el-button
              >
              <el-button @click="resetForm('formRef')">重置</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="tablesCard bgfff">
      <div class="tablesCardTop">
        <div></div>
        <el-button
          v-if="type == 2"
          type="primary"
          size="small"
          @click="addPeopleShow = true"
          >新增成员</el-button
        >
      </div>
      <el-table
        v-show="type == 1"
        :data="tableData"
        border
        size="small"
        style="width: 100%"
      >
        <!-- height="580" -->
        <el-table-column prop="_code" label="序号" align="center" width="80">
        </el-table-column>
        <el-table-column prop="name" label="活动标题" align="center">
        </el-table-column>
        <el-table-column prop="address" label="活动地点" align="center" />
        <el-table-column prop="time" label="活动时间" align="center">
          <template slot-scope="scope">
            {{ scope.row.begin_time }}~{{ scope.row.end_time }}
          </template>
        </el-table-column>
        <el-table-column
          prop="sing_end_time"
          label="报名截止时间"
          align="center"
        />
        <el-table-column
          prop="point_num"
          label="活动积分"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <div style="color: #1890ff">
              系统积分{{ scope.row.point_num }}/人
            </div>
            <div style="color: #1890ff">
              荣誉积分{{ scope.row.honor_point_num }}/人
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="person_num_limit"
          label="活动人数上限"
          align="center"
        />
        <el-table-column prop="report_num" label="已报名人数" align="center" />
        <el-table-column prop="sign_num" label="已签到人数" align="center" />
        <el-table-column prop="status" label="上架状态" align="center">
          <template slot-scope="scope">
            <span style="color: #1890ff">{{
              scope.row.status == 1 ? "上架" : "下架"
            }}</span>
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          prop=""
          label="操作"
          align="center"
          width="230"
        >
          <template slot-scope="scope">
            <div class="operateBtns">
              <el-link type="primary" @click="onBtns(1, scope.row)"
                >查看</el-link
              ><el-divider direction="vertical"></el-divider>
              <el-link type="primary" @click="onBtns(2, scope.row)"
                >编辑</el-link
              ><el-divider direction="vertical"></el-divider>
              <el-popover
                :ref="`popover1-${scope.row.id}`"
                popper-class="myPopover"
                placement="left"
                width="160"
                trigger="click"
              >
                <p class="text">
                  <i class="el-icon el-icon-warning"></i>
                  {{ scope.row.status == 1 ? "是否确认下架" : "是否确认上架" }}
                </p>
                <div class="btnBox">
                  <el-button
                    size="mini"
                    @click="$refs[`popover1-${scope.row.id}`].doClose()"
                    >取消</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="onBtns(3, scope.row)"
                    >确定</el-button
                  >
                </div>
                <el-link type="primary" slot="reference">{{
                  scope.row.status == 1 ? "下架" : "上架"
                }}</el-link> </el-popover
              ><el-divider direction="vertical"></el-divider>
              <el-popover
                :ref="`popover-${scope.row.id}`"
                popper-class="myPopover"
                placement="left"
                width="160"
                trigger="click"
              >
                <p class="text">
                  <i class="el-icon el-icon-warning"></i>
                  是否确认删除？
                </p>
                <div class="btnBox">
                  <el-button
                    size="mini"
                    @click="$refs[`popover-${scope.row.id}`].doClose()"
                    >取消</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="onBtns(4, scope.row)"
                    >确定</el-button
                  >
                </div>
                <el-link type="danger" slot="reference">删除</el-link>
              </el-popover>
              <el-link
                type="primary"
                @click="onBtns(5, scope.row)"
                v-if="scope.row.is_can_cancel == 1"
                >{{
                  scope.row.is_cancel == 2 ? "取消活动" : "重新发布"
                }}</el-link
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <el-table
        v-show="type == 2"
        :data="tableData"
        border
        size="small"
        style="width: 100%"
      >
        <!-- height="580" -->
        <el-table-column prop="_code" label="序号" align="center" width="80">
        </el-table-column>
        <el-table-column prop="userName" label="姓名" align="center" />
        <el-table-column prop="mobile" label="手机号" align="center">
        </el-table-column>
        <el-table-column prop="idNo" label="身份证号" align="center" />
        <el-table-column prop="" label="身份" align="center">
          <template slot-scope="scope">
            {{ scope.row.type == 1 ? "社长" : "社团成员" }}
          </template>
        </el-table-column>

        <el-table-column prop="house.name" label="所在房屋" align="center" />
        <el-table-column prop="create_time" label="加入时间" align="center" />
        <el-table-column label="操作" align="center" width="150">
          <template slot-scope="scope">
            <div class="operateBtns">
              <el-popover
                :disabled="scope.row.type == 1"
                :ref="`remove-${scope.row.id}`"
                popper-class="myPopover"
                placement="left"
                width="160"
                trigger="click"
              >
                <p class="text">
                  <i class="el-icon el-icon-warning"></i>
                  是否移除社团？
                </p>
                <div class="btnBox">
                  <el-button
                    size="mini"
                    @click="$refs[`remove-${scope.row.id}`].doClose()"
                    >取消</el-button
                  >
                  <el-button
                    type="primary"
                    size="mini"
                    @click="onBtns(6, scope.row)"
                    >确定</el-button
                  >
                </div>
                <el-link
                  :disabled="scope.row.type == 1"
                  type="danger"
                  slot="reference"
                  >移除社团</el-link
                >
              </el-popover>
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="pageBlock">
        <el-pagination
          background
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          :current-page.sync="form.page"
          :page-size="form.limit"
          @size-change="
            (e) => {
              form.limit = e;
              getList();
            }
          "
          @current-change="
            (e) => {
              form.page = e;
              getList();
            }
          "
        >
        </el-pagination>
      </div>
    </div>
    <addClub
      v-if="addClubShow"
      @handleClose="
        (val) => {
          addClubShow = false;
          if (val) {
            getList();
          }
        }
      "
      :dialogVisible="addClubShow"
      :clubId="clubInfo.id"
    ></addClub>
    <el-dialog
      title="审核"
      width="350px"
      top="300px"
      :visible.sync="checkShow"
      :before-close="
        () => {
          checkShow = false;
        }
      "
    >
      <div class="checkdialogBody">
        <span>审核意见：</span>
        <el-radio-group v-model="radio">
          <el-radio :label="1">通过</el-radio>
          <el-radio :label="2">拒绝</el-radio>
        </el-radio-group>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click="checkShow = false">取 消</el-button>
        <el-button size="small" type="primary" @click="onCheck()"
          >确 定</el-button
        >
      </div>
    </el-dialog>
    <activeDetail
      v-if="activeDetailShow"
      @handleClose="activeDetailShow = false"
      :dialogVisible="activeDetailShow"
      :id="clubInfo.id"
    ></activeDetail>
    <addActivity
      v-if="addActivityShow"
      @handleClose="
        (val) => {
          addActivityShow = false;
          if (val) getList();
        }
      "
      :dialogVisible="addActivityShow"
      :id="clubInfo.id"
    ></addActivity>
    <addPeople
      v-if="addPeopleShow"
      @handleClose="
        (val) => {
          addPeopleShow = false;
          if (val) getList();
        }
      "
      :dialogVisible="addPeopleShow"
    >
    </addPeople>
  </div>
</template>

<script>
import {
  activeList,
  activeUpStatus,
  delActiveCancel,
  activeCancel,
} from "@/api/activity.js";
import { clubList, clubMemberList, delClubMember } from "@/api/club.js";
import addClub from "./common/addClub.vue";
import activeDetail from "@/views/activity/common/activeDetail.vue";
import addActivity from "@/views/activity/common/addActivity.vue";
import addPeople from "./common/addPeople.vue";

export default {
  name: "",
  props: [""],

  data() {
    return {
      type: "1",
      form: {
        name: "",
        address: "",
        status: "",
        club_id: this.$route.query.clubId,
        clubs_id: this.$route.query.clubId,
        type: "",
        page: 1,
        limit: 10,
      },
      tableData: [{}],
      total: 0,
      projectId: "",
      checkShow: false,
      radio: 1,

      addClubShow: false,
      clubInfo: {},

      activeDetailShow: false,
      addActivityShow: false,
      addPeopleShow: false,
    };
  },

  components: { addClub, activeDetail, addActivity, addPeople },

  computed: {},

  beforeMount() {},

  mounted() {
    this.getList();
  },

  methods: {
    onSubmit() {
      this.getList();
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.form = {
        name: "",
        address: "",
        status: "",
        club_id: this.$route.query.clubId,
        clubs_id: this.$route.query.clubId,
        type: "",
        page: 1,
        limit: 10,
      };
      this.getList();
    },
    getList() {
      if (this.type == 1) {
        //社团活动列表
        activeList(this.form).then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.data;
            this.total = res.data.count;
          }
        });
      } else {
        //社团成员列表
        clubMemberList(this.form).then((res) => {
          if (res.code == 200) {
            this.tableData = res.data.data;
            this.total = res.data.count;
          }
        });
      }
    },
    onBtns(val, info) {
      this.clubInfo = info;
      if (val == 1) {
        //查看
        this.activeDetailShow = true;
      } else if (val == 2) {
        //编辑
        this.addActivityShow = true;
      } else if (val == 3) {
        this.$refs[`popover1-${info.id}`].doClose();
        let status = "";
        if (info.status == 1) {
          status = 2;
        } else {
          status = 1;
        }
        //上架,下架
        activeUpStatus({
          id: info.id,
          status,
        }).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.getList();
          }
        });
      } else if (val == 4) {
        //删除
        this.$refs[`popover-${info.id}`].doClose();
        //删除
        delActiveCancel({
          id: info.id,
        }).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.getList();
          }
        });
      } else if (val == 5) {
        if (info.is_cancel == 2) {
          //取消活动
          this.$prompt("请输入取消原因", "", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
          })
            .then(({ value }) => {
              activeCancel({
                id: info.id,
                is_cancel: 1,
                cancel_content: value,
              }).then((res) => {
                if (res.code == 200) {
                  this.$message({
                    type: "success",
                    message: res.msg,
                  });
                  this.getList();
                }
              });
            })
            .catch(() => {});
        } else {
          // 重新发布
          activeCancel({
            id: info.id,
            is_cancel: 2,
          }).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: res.msg,
              });
              this.getList();
            }
          });
        }
        this.checkShow = true;
      } else if (val == 6) {
        //移除社团
        this.$refs[`remove-${info.id}`].doClose();
        delClubMember({
          id: info.id,
        }).then((res) => {
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: res.msg,
            });
            this.getList();
          }
        });
      }
    },

    handleClick(val) {
      if (this.type == 2) {
        this.form.status = 2;
      } else {
        this.form.status = "";
      }
      this.form.page = 1;
      this.getList();
    },
  },

  watch: {},
};
</script>
<style lang="scss" scoped>
.clubPage {
  .searchBox {
    margin-bottom: 14px;
    padding: 0 24px;
    display: flex;
    flex-direction: column;
    height: 147px;
    .tabsBox {
      position: relative;
      margin: 10px 0 20px;
      .el-tabs {
        display: flex;
        flex-direction: column;
        justify-content: center;
        .el-tabs__nav-wrap::after {
          background-color: rgba(0, 0, 0, 0);
        }
      }
      .el-button {
        position: absolute;
        right: 0;
        top: 0;
      }
    }
    /deep/.el-form-item {
      margin-bottom: 0;
      .el-input__inner {
        width: 180px;
      }
    }
  }
  .tablesCard {
  }
  .checkdialogBody {
    display: flex;
    justify-content: center;
    align-items: center;
    span {
      margin-bottom: 2px;
      margin-right: 10px;
    }
  }
}
</style>
